{$php_begin} include("../../system/include/header_no.php"){$php_end}{$crlf}

{$php_begin}{$crlf}
$id = get("button_id") ;
$action = get("system_action") ;
if($action == ""){
	$action = ($id == "") ? "{$tableName}_insert" : "{$tableName}_update";
}

if($action != "" && !hasPrivilege($action)){
	do_every("parent.popError('common.need_privilege,$action');");
	return ;
}

if($action == "{$tableName}_delete"){
	$sqlstr = "delete from {$tableName} where {$primaryKey} in (".get("button_ids").")";
	$flag = fullQuery($company["db_host"],$company["db_name"],$company["db_user"],$company["db_pass"],$sqlstr);
	if($flag == 1){
		do_every("parent.do_refresh();");
	}else{
		do_every("parent.popError('common.delete_failed');");
	}
	return ;
}

if($action == "{$tableName}_insert"){
	$matrix = getParameters();
	putEditorInfoIntoMatrix($matrix);
	$sqlstr = "insert into {$tableName} " . getInsertSQLBodyByMatrix($matrix) ;
	$flag = fullQuery($company["db_host"],$company["db_name"],$company["db_user"],$company["db_pass"],$sqlstr);
	if($flag == 1){
		do_every("parent.location = '{$tableName}_list.php';");
	}else{
		do_every("parent.popError('common.insert_failed');");
	}
}

if($action == "{$tableName}_update"){
	$matrix = getParameters();
	putEditorInfoIntoMatrix($matrix);
	$sqlstr = "update {$tableName} set " . getUpdateSQLBodyByMatrix($matrix) . " where {$primaryKey}=$id" ;
	$flag = fullQuery($company["db_host"],$company["db_name"],$company["db_user"],$company["db_pass"],$sqlstr);
	if($flag == 1){
		do_every("parent.location = '{$tableName}_list.php';");
	}else{
		do_every("parent.popError('common.update_failed');");
	}
}



{$php_end}{$crlf}

{$php_begin} include("../../system/include/footer_no.php"){$php_end}{$crlf}